﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace User.API.Data.Mapping
{
    public class UserPropertyMap
        : IEntityTypeConfiguration<UserProperty>
    {
        public void Configure(EntityTypeBuilder<UserProperty> builder)
        {
            //Table.
            builder.ToTable("UserProperty");

            //Key.
            builder.HasKey("AppUserId","Key","Value");

            //Property.
            builder.Property(t => t.Text)
                .HasColumnName("Text")
                .HasMaxLength(36)
                .IsUnicode(true)
                .IsRequired();
            builder.Property(t => t.Key)
               .HasColumnName("Key")
               .HasMaxLength(36)
               .IsUnicode(true)
               .IsRequired();
            builder.Property(t => t.Value)
               .HasColumnName("Value")
               .HasMaxLength(36)
               .IsUnicode(true)
               .IsRequired();


            //Relation.
            builder.HasOne(t => t.AppUser)
                .WithMany(t => t.Properties)
                .HasForeignKey(t => t.AppUserId);
                

        }
    }
}
